home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / info-service / www / src / fminit2.0 / html.ol < prev    next >
Encoding:
Text File  |  1992-11-17  |  5.4 KB  |  234 lines

  1. ;;; html.ol -- objective lisp support for the WWW HTML format
  2. ;;; $Id: html.ol,v 1.2 92/11/17 21:59:51 connolly Exp $
  3. ;;;
  4.  
  5. (require 'SGML)
  6.  
  7. (defClass HTML SGML
  8.   (ignore anchor-content)
  9.   )
  10.  
  11. (defMethod HTML :ascii (data)
  12.   ;; @@ watch out for </ in CDATA
  13.   (cond (ignore)
  14.     ((member (first gi-stack) '(XMP LISTING))
  15.      [self :format "~A" data]
  16.      )
  17.     (t
  18.      (flet ((sgml-markup (c)
  19.                  (member c '(#\& #\<)) )
  20.         )
  21.            (do* ((p (position-if #'sgml-markup data)
  22.             (position-if #'sgml-markup data))
  23.              )
  24.             ((null p)
  25.              [self :format "~A" data]
  26.              )
  27.             [self :format "~A&~A;" (subseq data 0 p)
  28.               (case (elt data p)
  29.                 (#\& '|amp|)
  30.                 (#\< '|lt|)
  31.                 )]
  32.             (setq data (subseq data (1+ p)))
  33.             ) )
  34.      ) )
  35.   (setq anchor-content t)
  36.   )
  37.  
  38. (defMethod HTML :end-record ()
  39.   ;; nothing
  40.   )
  41.  
  42. (defMethod HTML :started (gi)
  43.   (or (member gi gi-stack)
  44.       [self :start gi])
  45.   )
  46.  
  47. (defMethod HTML :ended (gi)
  48.   (do ()
  49.       ((null (member gi gi-stack)))
  50.       [self :end (first gi-stack)]
  51.       (send-super :end-record)
  52.       ) )
  53.  
  54. (defMethod HTML :restore (gi)
  55.   (do ()
  56.       ((eq gi (first gi-stack)))
  57.       [self :end (first gi-stack)]
  58.       (send-super :end-record)
  59.       ) )
  60.  
  61. (defMethod HTML :reset-paragraph-format (tag fmt)
  62.   (cond ((eq tag 'TITLE)
  63.      [self :started tag]
  64.      )
  65.     ((null (eq tag (first gi-stack)))
  66.      [self :started 'document]
  67.      [self :restore 'document]
  68.      [self :started tag])
  69.     )
  70.   (case tag
  71.     ((DIR MENU OL UL)
  72.      [self :empty 'LI])
  73.     (DL
  74.      [self :empty 'DT]
  75.      )
  76.   ) )
  77.  
  78. (defMethod HTML :reset-character-format (tag foo)
  79.   [self :end-anchor]
  80.   )
  81. (defMethod HTML :change-paragraph-format (foo)
  82.   )
  83. (defMethod HTML :change-character-format (foo)
  84.   [self :end-anchor]
  85.   )
  86. (defMethod HTML :save-character-format ()
  87.   (setq ignore t)
  88.   )
  89. (defMethod HTML :restore-character-format ()
  90.   (setq ignore nil)
  91.   )
  92.  
  93. (defMethod HTML :end-paragraph ()
  94.   [self :end-anchor]
  95.   (case (first gi-stack)
  96.     
  97.     (document
  98.      [self :empty 'P]
  99.      (send-super :end-record))
  100.     ((ul ol dir menu dl)
  101.      ;;nothing
  102.      )
  103.     (t [self :end (first gi-stack)]
  104.        (send-super :end-record))
  105.   ))
  106.  
  107. (defMethod HTML :end-section ()
  108.   [self :ended 'DOCUMENT]
  109.   )
  110.  
  111. (defMethod HTML :tab ()
  112.   [self :end-anchor]
  113.   (case (first gi-stack)
  114.     (DL
  115.      [self :empty 'DD]
  116.      )
  117.     ) )
  118.  
  119. (defMethod HTML :newline ()
  120.   (case (first gi-stack)
  121.     ((XMP LISTING)
  122.      (send-super :end-record)
  123.      )
  124.     ) )
  125.  
  126. (defMethod HTML :start-anchor (name href &aux attrs)
  127.   (if name (push `(name ,name) attrs))
  128.   (if href (push `(href ,href) attrs))
  129.   [self :start 'a attrs]
  130.   (setq anchor-content nil)
  131.   )
  132.  
  133. (defMethod HTML :end-anchor ()
  134.   (if anchor-content [self :ended 'a])
  135.   )
  136.  
  137. (defMethod HTML :mif-chars (chars)
  138.   ;; @@ watch out for </ in CDATA
  139.   (or ignore
  140.       (dolist (c chars)
  141.           (let ((i (char-int c))
  142.             (cdata (member (first gi-stack) '(XMP LISTING)))
  143.             )
  144.         [self :format "~A"
  145.               (cond ((and (null cdata) (eq c #\&)) "&")
  146.                 ((and (null cdata) (eq c #\<)) "<")
  147.                 ((< i 32) "_") ;;@@
  148.                 ((< i 128) c)
  149.                 (t (aref *FrameCharacterSet* (- i 128)))
  150.                 ) ] )
  151.           ) ) )
  152.  
  153. (setq *FrameCharacterSet*
  154.   #(
  155. |Adieresis| |Aring| |Ccedilla| |Eacute| 
  156. |Ntilde| |Odieresis| |Udieresis| |aacute| |agrave| 
  157. |acircumflex| |adieresis| |atilde| |aring| |ccedilla| 
  158. |eacute| |egrave| |ecircumflex| |edieresis| |iacute| 
  159. |igrave| |icircumflex| |idieresis| |ntilde| |oacute| 
  160. |ograve| |ocircumflex| |odieresis| |otilde| |uacute| 
  161. |ugrave| |ucircumflex| |udieresis| |dagger| nil |cent| 
  162. |sterling| |section| "*" |paragraph| |germandbls| 
  163. "(R)" "(C)" "(TM)" |acute| |dieresis| 
  164. nil |AE| |Oslash| nil nil nil nil |yen| nil nil nil 
  165. nil nil nil |ordfeminine| |ordmasculine| nil |ae| |oslash| 
  166. |questiondown| |exclamdown| |logicalnot| nil |florin| 
  167. nil nil |guillemotleft| |guillemotright| |ellipsis| 
  168. nil |Agrave| |Atilde| |Otilde| |OE| |oe| "-" "--" 
  169. "``" "''" "`" "'" 
  170. nil nil |ydieresis| |Ydieresis| |fraction| "$"
  171. "<" ">" "fi" "fl" |daggerdbl| 
  172. "*" "," ",," |perthousand| 
  173. |Acircumflex| |Ecircumflex| |Aacute| |Edieresis| |Egrave| 
  174. |Iacute| |Icircumflex| |Idieresis| |Igrave| |Oacute| 
  175. |Ocircumflex| nil |Ograve| |Uacute| |Ucircumflex| |Ugrave| 
  176. |dotlessi| |circumflex| "~" |macron| |breve| |dotaccent| 
  177. |ring| |cedilla| |hungarumlaut| |ogonek| |caron| 
  178.     ) )
  179.  
  180. (defMethod HTML :marker (type text)
  181.   (case type
  182.     (8 (let* ((str (make-string-input-stream text))
  183.           (command (read str))
  184.           )
  185.          (case command
  186.            (newlink (peek-char t str)
  187.                 [self :start-anchor (read-line str) nil])
  188.            (gotolink [self :start-anchor nil (read-href str)])
  189.            (message (let ((client (read str))
  190.                   )
  191.                   (peek-char t str) ;; skip whitespace
  192.                   (case client
  193.                     (www [self :start-anchor nil
  194.                            (read-line str)] )
  195.                     ) ))
  196.            )
  197.          ))
  198.     ) )
  199.  
  200. (defun read-href (str)
  201.   ;; parse foo:bar -> file:foo#bar
  202.   ;;       bar -> #bar
  203.   ;;       foo:firstpage -> file:foo
  204.   (peek-char t str)
  205.   (do (file
  206.        anchor ex
  207.        href
  208.        (char (read-char str) (read-char str))
  209.        )
  210.       ((null char) ;; reached end of string
  211.        (if file
  212.        (setq href (concatenate 'string "file:" file)) )
  213.        (cond ((null anchor) )
  214.          ((eq 'firstpage (intern (concatenate 'string anchor))) )
  215.          (t (setq href (concatenate 'string href "#"
  216.                     anchor) )) )
  217.        href
  218.        )
  219.       
  220.       ;; body of do loop...
  221.       (case char
  222.         (#\: (setq file anchor)
  223.          (setq anchor nil)
  224.          (setq ex nil) )
  225.         (t (let ((cell (cons char nil))
  226.              )
  227.          (if ex (setf (cdr ex) cell)
  228.            (setf anchor cell) )
  229.          (setf ex cell) ))
  230.         )
  231.       ) )
  232.  
  233. (provide 'html)
  234.